package DemoText;

/**
 * 消失的两个数字
 */
public class LeetCode1719 {
    public int[] missingTwo(int[] nums) {
        int len = nums.length;
        int n = len + 2;
        int sum = 0;
        for (int i = 0; i < len; i++) sum ^= nums[i];
        for (int i = 1; i <= n; i++) sum ^= i;
        int j = 0;
        for (j = 0; j < 32; j++) {
            if (((sum >> j) & 1) == 1) break;
        }
        int[] ret = new int[2];
        for (int i = 0; i < len; i++) {
            if (((nums[i] >> j) & 1) == 1) ret[0] ^= nums[i];
            else ret[1] ^= nums[i];
        }
        for (int i = 1; i <= n; i++) {
            if (((i >> j) & 1) == 1) ret[0] ^= i;
            else ret[1] ^= i;
        }
        return ret;
    }
}
